const path = require('path')
// const vConsolePlugin = require('vconsole-webpack-plugin')

function resolve(dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  chainWebpack: (config) => {
    config.resolve.alias
      .set('@', resolve('src'))
      .set('@api', resolve('src/api'))
      .set('@views', resolve('src/views'))
      .set('@assets', resolve('src/assets'))
      .set('@utils', resolve('src/utils'))
      .set('@comp', resolve('src/components'))

    const fileRule = config.module.rule('file')
    fileRule.uses.clear()
    fileRule
      .test(/\.pdf|ico$/)
      .use('file-loader')
      .loader('file-loader')
      .options({
        limit: 10000
      })
  },
  // configureWebpack: config => {
  //   // 生产环境去掉vconsole调试器
  //   const envType = process.env.NODE_ENV !== 'production'
  //   const pluginsDev = [
  //     // eslint-disable-next-line new-cap
  //     new vConsolePlugin({
  //       filter: [],
  //       enable: envType
  //     })
  //   ]

  //   config.plugins = [...config.plugins, ...pluginsDev]
  // },
  publicPath: './',

  devServer: {
    proxy: {
      '/api': {
        // target: 'http://localhost:3000/', // 本地后端地址
        target: 'http://101.132.181.9:3000/', // 线上后端地址
        changeOrigin: true, //允许跨域
        pathRewrite: {
          '^/api': ''
        }
      }
    }
  }
}
